package com.example.Activity;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.example.training.R;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;

public class FileDetailActivity extends Activity {
    private ListView _list_file;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.filedetail_activity);
        _list_file = (ListView)findViewById(R.id.filedetail_list);
        String path = getIntent().getStringExtra("path");
        LoadFileInfo(path);
    }

    private void LoadFileInfo(String path){
        File file = new File(path);
        ArrayList<HashMap<String, Object>> items = new ArrayList<HashMap<String, Object>>();
        items.add(MakeProperty("文件名：", file.getName()));
        items.add(MakeProperty("全路径：", file.getAbsolutePath()));
        items.add(MakeProperty("文件大小：", Long.toString(file.getTotalSpace())));

        _list_file.setAdapter(new SimpleAdapter(this,items,
                                R.layout.filedetail_liststyle,
                                new String[] {"key","value"},
                                new int[] {R.id.text_property_key,R.id.text_property_value}
                                )
        );
    }

    private HashMap<String, Object> MakeProperty(String key, String value){
        HashMap<String, Object> item = new HashMap<String, Object>();
        item.put("key", key);
        item.put("value", value);
        return item;
    }
}
